
[ToolboxItem("ToolboxItemType = null", "ToolboxItemTypeName = ")] [DesignTimeVisible("Visible = False")] [DefaultProperty("Content")] [ContentProperty("Content")] [Localizability(None)] [StyleTypedProperty("Property = FocusVisualStyle", "StyleTargetType = System.Windows.Controls.Control")] [XmlLangProperty("Name = Language")] [UsableDuringInitialization("Usable = True")] [RuntimeNameProperty("Name = Name")] [UidProperty()] [TypeDescriptionProvider("TypeName = MS.Internal.ComponentModel.DependencyObjectProvider")] [NameScopeProperty("Name = NameScope", "Type = System.Windows.NameScope")] public class WpfHighlightTool<T> : WpfVisualTool where T: class, Vintasoft.Imaging.Wpf.IWpfBoundedObject
[ToolboxItem("ToolboxItemType = null", "ToolboxItemTypeName = ")] [DesignTimeVisible("Visible = False")] [DefaultProperty("Content")] [ContentProperty("Content")] [Localizability(None)] [StyleTypedProperty("Property = FocusVisualStyle", "StyleTargetType = System.Windows.Controls.Control")] [XmlLangProperty("Name = Language")] [UsableDuringInitialization("Usable = True")] [RuntimeNameProperty("Name = Name")] [UidProperty()] [TypeDescriptionProvider("TypeName = MS.Internal.ComponentModel.DependencyObjectProvider")] [NameScopeProperty("Name = NameScope", "Type = System.Windows.NameScope")] public __gc class WpfHighlightTool<T> : public WpfVisualTool* where T: class, Vintasoft.Imaging.Wpf.IWpfBoundedObject*
[ToolboxItem("ToolboxItemType = null", "ToolboxItemTypeName = ")] [DesignTimeVisible("Visible = False")] [DefaultProperty("Content")] [ContentProperty("Content")] [Localizability(None)] [StyleTypedProperty("Property = FocusVisualStyle", "StyleTargetType = System.Windows.Controls.Control")] [XmlLangProperty("Name = Language")] [UsableDuringInitialization("Usable = True")] [RuntimeNameProperty("Name = Name")] [UidProperty()] [TypeDescriptionProvider("TypeName = MS.Internal.ComponentModel.DependencyObjectProvider")] [NameScopeProperty("Name = NameScope", "Type = System.Windows.NameScope")] generic<typename T> public ref class WpfHighlightTool : public WpfVisualTool^ where T: ref class, Vintasoft.Imaging.Wpf.IWpfBoundedObject^
'Declaration <ToolboxItemAttribute("ToolboxItemType = null", "ToolboxItemTypeName = ")> <DesignTimeVisibleAttribute("Visible = False")> <DefaultPropertyAttribute("Content")> <ContentPropertyAttribute("Content")> <LocalizabilityAttribute(None)> <StyleTypedPropertyAttribute("Property = FocusVisualStyle", "StyleTargetType = System.Windows.Controls.Control")> <XmlLangPropertyAttribute("Name = Language")> <UsableDuringInitializationAttribute("Usable = True")> <RuntimeNamePropertyAttribute("Name = Name")> <UidPropertyAttribute()> <TypeDescriptionProviderAttribute("TypeName = MS.Internal.ComponentModel.DependencyObjectProvider")> <NameScopePropertyAttribute("Name = NameScope", "Type = System.Windows.NameScope")> Public Class WpfHighlightTool (Of T{b}T{/b} must be a class that implements T:Vintasoft.Imaging.Wpf.IWpfBoundedObject interface.As Class, Vintasoft.Imaging.Wpf.IWpfBoundedObject}) Inherits WpfVisualTool
Этот код C#/VB.NET показывает, как выделить набор прямоугольников на изображении в WPF просмотрщике изображений.
Public Sub AddRectanglesOnImageInWpfImageViewer(viewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewer) Dim random As New System.Random() ' create a set of random red rectangles Dim redObjects As New Vintasoft.Imaging.Wpf.UI.VisualTools.WpfColoredObjects(Of WpfHightlightRectangle)(CreateRandomHightlightRectangles(random, viewer.Image.Width, viewer.Image.Height, 16)) ' set the brush for red rectangles redObjects.Brush = New System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(128, 255, 0, 0)) ' set the pen for red rectangles redObjects.Pen = New System.Windows.Media.Pen(New System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(64, 0, 0, 0)), 1) ' create a set of random green rectangles Dim greenObjects As New Vintasoft.Imaging.Wpf.UI.VisualTools.WpfColoredObjects(Of WpfHightlightRectangle)(CreateRandomHightlightRectangles(random, viewer.Image.Width, viewer.Image.Height, 16)) ' set the brush for green rectangles greenObjects.Brush = New System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(128, 0, 255, 0)) ' set the pen for green rectangles greenObjects.Pen = New System.Windows.Media.Pen(New System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(64, 0, 0, 0)), 1) ' create a set of random blue rectangles Dim blueObjects As New Vintasoft.Imaging.Wpf.UI.VisualTools.WpfColoredObjects(Of WpfHightlightRectangle)(CreateRandomHightlightRectangles(random, viewer.Image.Width, viewer.Image.Height, 16)) ' set the brush for blue rectangles blueObjects.Brush = New System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(128, 0, 0, 255)) ' set the pen for blue rectangles blueObjects.Pen = New System.Windows.Media.Pen(New System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(64, 0, 0, 0)), 1) ' create the visual tool for highlighting rectangles on image in image viewer Dim highlightTool As New Vintasoft.Imaging.Wpf.UI.VisualTools.WpfHighlightTool(Of WpfHightlightRectangle)() ' add red rectangles to the visual tool highlightTool.Items.Add(redObjects) ' add green rectangles to the visual tool highlightTool.Items.Add(greenObjects) ' add blue rectangles to the visual tool highlightTool.Items.Add(blueObjects) ' set the HighlightTool as the active visual tool in image viewer, ' i.e. show the rectangles on image in image viewer viewer.VisualTool = highlightTool End Sub ''' <summary> ''' Creates an array with random rectangles on image. ''' </summary> Private Function CreateRandomHightlightRectangles(random As System.Random, imageWidth As Integer, imageHeight As Integer, rectCount As Integer) As WpfHightlightRectangle() Dim objects As WpfHightlightRectangle() = New WpfHightlightRectangle(rectCount - 1) {} For i As Integer = 0 To rectCount - 1 Dim x As Integer = random.[Next](imageWidth) Dim y As Integer = random.[Next](imageHeight) Dim width As Integer = random.[Next](System.Math.Min(100, imageWidth - x)) Dim height As Integer = random.[Next](System.Math.Min(100, imageHeight - y)) objects(i) = New WpfHightlightRectangle(New System.Windows.Rect(x, y, width, height)) Next Return objects End Function ''' <summary> ''' A rectangle that must be highlighted on image in image viewer. ''' </summary> Public Class WpfHightlightRectangle Implements Vintasoft.Imaging.Wpf.IWpfBoundedObject Private _rect As System.Windows.Rect Public Sub New(rect As System.Windows.Rect) _rect = rect End Sub Public Function GetBoundingBox() As System.Windows.Rect Implements Vintasoft.Imaging.Wpf.IWpfBoundedObject.GetBoundingBox Return _rect End Function End Class
public void AddRectanglesOnImageInWpfImageViewer(Vintasoft.Imaging.Wpf.UI.WpfImageViewer viewer) { System.Random random = new System.Random(); // create a set of random red rectangles Vintasoft.Imaging.Wpf.UI.VisualTools.WpfColoredObjects<WpfHightlightRectangle> redObjects = new Vintasoft.Imaging.Wpf.UI.VisualTools.WpfColoredObjects<WpfHightlightRectangle>( CreateRandomHightlightRectangles(random, viewer.Image.Width, viewer.Image.Height, 16)); // set the brush for red rectangles redObjects.Brush = new System.Windows.Media.SolidColorBrush( System.Windows.Media.Color.FromArgb(128, 255, 0, 0)); // set the pen for red rectangles redObjects.Pen = new System.Windows.Media.Pen( new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(64, 0, 0, 0)), 1); // create a set of random green rectangles Vintasoft.Imaging.Wpf.UI.VisualTools.WpfColoredObjects<WpfHightlightRectangle> greenObjects = new Vintasoft.Imaging.Wpf.UI.VisualTools.WpfColoredObjects<WpfHightlightRectangle>( CreateRandomHightlightRectangles(random, viewer.Image.Width, viewer.Image.Height, 16)); // set the brush for green rectangles greenObjects.Brush = new System.Windows.Media.SolidColorBrush( System.Windows.Media.Color.FromArgb(128, 0, 255, 0)); // set the pen for green rectangles greenObjects.Pen = new System.Windows.Media.Pen( new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(64, 0, 0, 0)), 1); // create a set of random blue rectangles Vintasoft.Imaging.Wpf.UI.VisualTools.WpfColoredObjects<WpfHightlightRectangle> blueObjects = new Vintasoft.Imaging.Wpf.UI.VisualTools.WpfColoredObjects<WpfHightlightRectangle>( CreateRandomHightlightRectangles(random, viewer.Image.Width, viewer.Image.Height, 16)); // set the brush for blue rectangles blueObjects.Brush = new System.Windows.Media.SolidColorBrush( System.Windows.Media.Color.FromArgb(128, 0, 0, 255)); // set the pen for blue rectangles blueObjects.Pen = new System.Windows.Media.Pen( new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(64, 0, 0, 0)), 1); // create the visual tool for highlighting rectangles on image in image viewer Vintasoft.Imaging.Wpf.UI.VisualTools.WpfHighlightTool<WpfHightlightRectangle> highlightTool = new Vintasoft.Imaging.Wpf.UI.VisualTools.WpfHighlightTool<WpfHightlightRectangle>(); // add red rectangles to the visual tool highlightTool.Items.Add(redObjects); // add green rectangles to the visual tool highlightTool.Items.Add(greenObjects); // add blue rectangles to the visual tool highlightTool.Items.Add(blueObjects); // set the HighlightTool as the active visual tool in image viewer, // i.e. show the rectangles on image in image viewer viewer.VisualTool = highlightTool; } /// <summary> /// Creates an array with random rectangles on image. /// </summary> private WpfHightlightRectangle[] CreateRandomHightlightRectangles( System.Random random, int imageWidth, int imageHeight, int rectCount) { WpfHightlightRectangle[] objects = new WpfHightlightRectangle[rectCount]; for (int i = 0; i < rectCount; i++) { int x = random.Next(imageWidth); int y = random.Next(imageHeight); int width = random.Next(System.Math.Min(100, imageWidth - x)); int height = random.Next(System.Math.Min(100, imageHeight - y)); objects[i] = new WpfHightlightRectangle( new System.Windows.Rect(x, y, width, height)); } return objects; } /// <summary> /// A rectangle that must be highlighted on image in image viewer. /// </summary> public class WpfHightlightRectangle : Vintasoft.Imaging.Wpf.IWpfBoundedObject { System.Windows.Rect _rect; public WpfHightlightRectangle(System.Windows.Rect rect) { _rect = rect; } public System.Windows.Rect GetBoundingBox() { return _rect; } }
System.Object
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.Visual
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Control
System.Windows.Controls.ContentControl
Vintasoft.Imaging.Wpf.UI.VisualTools.WpfVisualTool
Vintasoft.Imaging.Wpf.UI.VisualTools.WpfHighlightTool<T>
Целевые платформы: .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5